import { createNavigationContainerRef } from '@react-navigation/native';

// 创建导航引用
export const navigationRef = createNavigationContainerRef();

// 导航到指定页面
export function navigate(name: string, params?: object) {
  if (navigationRef.isReady()) {
    // @ts-ignore
    navigationRef.navigate(name, params);
  }
}

// 返回上一页
export function goBack() {
  if (navigationRef.isReady() && navigationRef.canGoBack()) {
    navigationRef.goBack();
  }
}

// 重置导航堆栈
export function reset(name: string, params?: object) {
  if (navigationRef.isReady()) {
    navigationRef.reset({
      index: 0,
      routes: [{ name, params }],
    });
  }
} 